#ifndef LOCALPLAYER_H
#define LOCALPLAYER_H

#include <game/player.h>

#include <QHostAddress>

class KeyManager;
class QUdpSocket;

class LocalPlayer : public Player
{
    Q_OBJECT;
public:
    LocalPlayer(PWorld *world, PVector startPos, double startAngle, QString name, KeyManager *manager, QObject *parent = 0, bool createShip = true);
    LocalPlayer(Player *player, KeyManager *manager, PWorld *world);

    Qt::Key getKeyUp() const;
    Qt::Key getKeyDown() const;
    Qt::Key getKeyRight() const;
    Qt::Key getKeyLeft() const;

    void setKeys(Qt::Key up, Qt::Key down, Qt::Key right, Qt::Key left);

    void serialize(QDomDocument *doc, QDomElement *e) const;

    static LocalPlayer *deserialize(QDomNode e, PWorld *world, KeyManager *manager);

    QString getType() const;

    void setSocket(QUdpSocket *socket, QHostAddress address, int port);

private slots:
    void sendAccelerate();
    void sendFire();
    void sendLeft();
    void sendRight();

    void sendNAccelerate();
    void sendNFire();
    void sendNLeft();
    void sendNRight();

private:
    Qt::Key myKeyUp;
    Qt::Key myKeyDown;
    Qt::Key myKeyRight;
    Qt::Key myKeyLeft;
    KeyManager *myKeyManager;

    QUdpSocket *mySocket;
    QHostAddress myServerAddr;
    int myPort;
};

#endif // LOCALPLAYER_H
